<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>博客管理页面</title>
	<link rel="stylesheet" type="text/css"
		  href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css"
		  href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/themes/icon.css">
	<script type="text/javascript"
			src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/jquery.min.js"></script>
	<script type="text/javascript"
			src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
	<script type="text/javascript"
			src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/bootstrap3/css/bootstrap.min.css"
		  integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
	<script src="${pageContext.request.contextPath}/static/bootstrap3/js/bootstrap.min.js"
			integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
			crossorigin="anonymous"></script>
	<script type="text/javascript">

		function formatBlogType(val, row) {
			return val.typeName;
		}

		function formatTitle(val, row) {
			return "<a target='_blank' href='${pageContext.request.contextPath}/blog/articles/" + row.id + ".html'>" + val + "</a>"
		}

		function searchBlog() {
			$("#dg").datagrid('load', {
				"title": $("#s_title").val()
			});
		}

		function deleteBlog() {
			var selectedRows = $("#dg").datagrid("getSelections");
			if (selectedRows.length == 0) {
				$.messager.alert("系统提示", "请选择要删除的数据！");
				return;
			}
			var strIds = [];
			for (var i = 0; i < selectedRows.length; i++) {
				strIds.push(selectedRows[i].id);
			}
			var ids = strIds.join(",");
			$.messager.confirm("系统提示", "您确定要删除这<font color=red>" + selectedRows.length + "</font>条数据吗？",
					function (r) {
						if (r) {
							$.post("${pageContext.request.contextPath}/admin/adminBlogServlet?way=deleteBlog&",
									{
										ids: ids
									},
									function (result) {
										if (result == "success") {
											$.messager.alert("系统提示", "数据已成功删除！");
											$("#dg").datagrid("reload");
										} else {
											$.messager.alert("系统提示", "数据删除失败！");
										}
									}, "json"
							);
						}
					}
			);
		}

		function openBlogModifyTab() {
			var selectedRows = $("#dg").datagrid("getSelections");
			if (selectedRows.length != 1) {
				$.messager.alert("系统提示", "请选择一个要修改的博客！");
				return;
			}
			var row = selectedRows[0];
			window.parent.openTab('修改博客', 'modifyBlog.jsp?id=' + row.id, 'icon-writeblog');
		}

		/*$(function (){
            location.reload(true);
        })*/
	</script>
</head>
<body style="margin: 1px">
<table id="dg" title="博客管理" class="easyui-datagrid" class="table table-hover"
	   fitColumns="true" pagination="true" rownumbers="true"
	   url="${pageContext.request.contextPath}/admin//blogManagerServlet?method=getAllBlogAndType" fit="true"
	   toolbar="#tb">
	<thead>
	<tr>
		<th field="cb" checkbox="true" align="center" width="30"></th>
		<th field="id" width="60" align="center">编号</th>
		<th field="title" width="400" align="center" formatter="formatTitle">标题</th>
		<th field="releaseDate" width="300" align="center">发布日期</th>
		<th field="blogType" width="200" align="center" <%--formatter="formatBlogType"--%>>博客类别</th>
	</tr>
	</thead>
	<tbody>
	<c:forEach var="item" items="${getBlogAndBlogTypeList}">
		<tr>
			<td></td>
			<td width="60" align="center">${item.id}</td>
			<td width="400" align="center">${item.title}</td>
			<td width="200" align="center">${item.releaseDate}</td>
			<td width="200" align="center">${item.blogType.typeName}</td>
		</tr>
	</c:forEach>
	</tbody>
</table>
<div id="tb">
	<div>
		<a href="javascript:openBlogModifyTab()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
		<a href="javascript:deleteBlog()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
	</div>
	<div>
		&nbsp;标题：&nbsp;<input type="text" id="s_title" size="20" onkeydown="if(event.keyCode==13) searchBlog()"/><a href="javascript:searchBlog()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
	</div>
</div>
</body>
</html>